﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Simulacion.Distributions
{
    /// <summary>
    /// Generic class of the LogNormal distribution.
    /// </summary>
    static class Lognormal
    {
        /// <summary>
        /// Gets the value using the Lognormal distribution.
        /// </summary>
        /// <returns>The value of the distribution.</returns>
        public static double GetDistributionValue(double sigma, double miu, double gama)
        {
            double variance, mediaY, varY, sigmaY;

            variance = Math.Pow(sigma, 2);

            mediaY = Math.Log(miu) - 0.5 * Math.Log(Math.Pow(variance / miu, 2) + 1);

            varY = Math.Log(Math.Pow(variance / miu, 2) + 1);

            sigmaY = Math.Sqrt(varY);

            double randomNumbers = 0;
            for (int i = 0; i < 12; i++)
            {
                randomNumbers += NumberGenerator.Generator.NextNumber;
            }

            double logNormal = Math.Exp(mediaY + sigmaY * (randomNumbers - 6));

            return logNormal / 7;
        }
    }
}
